<?php
/**
 * Created by PhpStorm.
 * User: Xwen
 * Date: 2018/12/15
 * Time: 23:22
 *
 *          ┌─┐       ┌─┐
 *       ┌──┘ ┴───────┘ ┴──┐
 *       │                 │
 *       │       ───       │
 *       │  ─┬┘       └┬─  │
 *       │                 │
 *       │       ─┴─       │
 *       │                 │
 *       └───┐         ┌───┘
 *           │         │
 *           │         │
 *           │         │
 *           │         └──────────────┐
 *           │                        │
 *           │                        ├─┐
 *           │                        ┌─┘
 *           │                        │
 *           └─┐  ┐  ┌───────┬──┐  ┌──┘
 *             │ ─┤ ─┤       │ ─┤ ─┤
 *             └──┴──┘       └──┴──┘
 *                 神兽保佑
 *                 代码无BUG!
 *"The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.”- Seymour Cray
 */
namespace app\admin\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        'id'            =>  'require|integer',
        'username'      =>  'require|min:2',
        'mobile'        =>  'require|length:11',
        'email'         =>  'require|email',
        'birthday'      =>  'require|date',
        'password'      =>  'require|min:6',
        'role_ids'      =>  'array'
    ];
    protected $message = [
        'id.require'          =>  '缺少用户ID',
        'id.integer'          =>  '用户id必须是整数',
        'username.require'    =>  '缺少用户名',
        'username.min'        =>  '用户名长度至少两位',
        'mobile.require'      =>  '缺少手机号信息',
        'mobile.length'       =>  '手机号长度必须为11位',
        'mobile.integer'      =>  '手机号格式不正确',
        'email.require'       =>  '缺少邮箱信息',
        'email.email'         =>  '邮箱格式不正确',
        'birthday.require'    =>  '缺少生日信息',
        'birthday.date'       =>  '生日信息不正确',
        'password.require'    =>  '未设置密码',
        'password.min'        =>  '密码长度必须大于6位',
    ];

    protected $scene = [
        'add'   =>  ['username', 'mobile', 'email', 'birthday', 'password', 'role_ids'],
        'delete'   =>  ['id'],
    ];

    public function sceneEdit(){
        return $this->remove('password', 'require')->append('id', 'require|integer');
    }

}